<%@ page language="java" import="com.newcrm.config.*,com.newcrm.util.Util,java.net.URLEncoder,com.newcrm.bean.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
    // 获取产品信息
    ProductInfo productInfo = Config.getInstance().productInfo;
    String productName = productInfo.productName;
    String companyHref = productInfo.companyHref;
 %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title><%=productName%> 安装向导</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta name="renderer" content="webkit"/>
  <meta http-equiv=X-UA-Compatible content="IE=EmulateIE7" />
  <link rel="shortcut icon" href="<%=request.getContextPath()%>/images/qikebao.ico" />
  <link href="<%=request.getContextPath()%>/css/setup<%=productInfo.logoImageExtInfo%>.css?ver=<%=Const.VERSION%>" media="screen" rel="stylesheet" type="text/css" />
  <script type="text/javascript" src="<%=request.getContextPath()%>/script/jquery-1.11.1.min.js"></script>
  <script>

    $(function() {
      <% if ("1".equals(productInfo.activeCodeFlag)) {%>
      var _checkSN = false;
      <% } else {%>
      var _checkSN = true;
      <% } %>
      $('#setupFrom').submit(function(event){
        if (!_checkSN) {
          checkSN();
          return false;
        }
        var _dbuser = $("#dbUser");
        if (_dbuser.val() == "") {
          alert("请输入数据库用户名");
          _dbuser.focus();
          return false;
        }

        var _companyname = $("#companyName");
        if (_companyname.val() == "") {
          alert("请输入公司名称");
          _companyname.focus();
          return false;
        }

        var _userid = $("#userId");
        if (_userid.val() == "") {
          alert("请输入管理员账号");
          _userid.focus();
          return false;
        }

        var _password = $("#userPassword");
        if (_password.val() == "") {
          alert("请输入管理员密码");
          _password.focus();
          return false;
        }

        var _password2 = $("#userPassword2");
        if (_password.val() != _password2.val()) {
          alert("管理员密码和重复密码不一致");
          _password2.focus();
          return false;
        }

        var _dbIp = $("#dbIp");
        if (_dbIp.val() == "") {
          alert("请输入数据库服务器的IP或机器名");
          _dbIp.focus();
          return false;
        }

        var _dbPort = $("#dbPort");
        if (_dbPort.val() == "") {
          alert("请输入数据库服务的端口号");
          _dbPort.focus();
          return false;
        }
        return true;
      });

      $("#link_ext").click(function(e) {
        e.preventDefault();
        $("#dbTable").show();
      });

      function checkSN() {
        var _companyId = $("#companyId");
        if (_companyId.val() == "") {
          alert("请输入注册公司ID");
          _companyId.focus();
          return;
        }

        var _activeCode = $("#activeCode");
        if (_activeCode.val() == "") {
          alert("请输入激活码");
          _activeCode.focus();
          return;
        }

        var _params = {};
        _params.companyId2 = _companyId.val();
        _params.activeCode = _activeCode.val();
        $.ajax({
          url: '<%=request.getContextPath()%>/setup/activeCode?random=' + Math.random(),
          type: 'GET',
          data:_params,
          dataType: 'json',
          timeout: 60000,
          error: function(){
            _checkSN = false;
          },
          success: function(json){
            if (json.error == "0") {
              _checkSN = true;
              alert("注册码激活成功！支持用户数："+json.licenceNum);
              $("#checkCode").val(json.checkCode);
              $("#companyId2").val(json.companyId2);
              $("#licenceNum").val(json.licenceNum);
              $("#expiredDate").val(json.expiredDate);
              $("#setupFrom").submit();
            } else {
              alert(json.msg);
              _checkSN = false;
            }
          }
        });
      }

    });
  </script>
</head>
<body>
  <div class="container">
    <div class="header">
      <div class="header-title">
        <h1><%=productName%> 安装向导</h1>
        <span>新一代客户管理平台</span>
      </div>
      <div class="setup step2">
        <h2>开始安装</h2>
        <p>设置公司基本信息</p>
      </div>
      <div class="stepstat">
        <ul>
          <li class="activated">1</li>
          <li class="current">2</li>
          <li class="unactivated">3</li>
          <li class="unactivated last">4</li>
          </ul>
        <div class="stepstatbg stepstat2"></div>
      </div>
    </div>
    <div class="main">
      <form method="post" id="setupFrom" action="<%=request.getContextPath()%>/setup/step2">
      <input type="hidden" name="agent" value="" size="35">
      <div><br />
        <% if ("1".equals(productInfo.activeCodeFlag)) {%>
        <div class="desc"><b>填写激活码信息</b></div>
        <table class="tb2">
        <tr><th class="tbopt">&nbsp;注册公司ID:</th>
        <td><input type="text" id="companyId" name="companyId" value="" size="35" class="txt"></td>
        <td>&nbsp;</td>
        </tr>

        <tr><th class="tbopt">&nbsp;激活码:</th>
        <td><input type="text" id="activeCode" name="activeCode" value="" size="35" class="txt"></td>
        <td><input type="hidden" id="checkCode" name="checkCode" value="" size="35"></td>
        <td><input type="hidden" id="companyId2" name="companyId2" value="" size="35"></td>
        <td><input type="hidden" id="licenceNum" name="licenceNum" value="" size="35"></td>
        <td><input type="hidden" id="expiredDate" name="expiredDate" value="" size="35"></td>
        <td>&nbsp;</td>
        </tr>
        </table>
        <% }%>
        <div class="desc"><b>填写管理员信息</b></div>
        <table class="tb2">
        <tr><th class="tbopt">&nbsp;公司名称:</th>
        <td><input type="text" id="companyName" name="companyName" value="" size="35" class="txt"></td>
        <td>&nbsp;</td>
        </tr>

        <tr><th class="tbopt">&nbsp;管理员账号:</th>
        <td><input type="text" id="userId" name="userId" value="admin" readonly size="35" class="txt"></td>
        <td>&nbsp;</td>
        </tr>

        <tr><th class="tbopt">&nbsp;管理员姓名:</th>
        <td><input type="text" id="userName" name="userName" value="" size="35" class="txt"></td>
        <td>&nbsp;</td>
        </tr>

        <tr><th class="tbopt">&nbsp;管理员密码:</th>
        <td><input type="password" id="userPassword" name="userPassword" value="" size="35" class="txt"></td>
        <td>&nbsp;管理员密码不能为空</td>
        </tr>

        <tr><th class="tbopt">&nbsp;重复密码:</th>
        <td><input type="password" id="userPassword2" name="userPassword2" value="" size="35" class="txt"></td>
        <td>&nbsp;</td>
        </tr>

        <tr><th class="tbopt">&nbsp;管理员 Email:</th>
        <td><input type="text" name="email" value="" size="35" class="txt"></td>
        <td>&nbsp;</td>
        </tr>

        <tr><th class="tbopt">&nbsp;联系电话:</th>
        <td><input type="text" name="tel" value="" size="35" class="txt"></td>
        <td>&nbsp;</td>
        </tr>

        <tr><th class="tbopt">&nbsp;联系QQ:</th>
        <td><input type="text" name="qq" value="" size="35" class="txt"></td>
        <td>&nbsp;</td>
        </tr>
        </table>

        <div class="desc"><b>数据库信息相关高级选项</b> (如需要使用其他数据库请点击展开，进行设置)【<a id="link_ext" href="#">＋展开</a>】</div>
        <table id="dbTable" class="tb2" style="display:none;">
        <tr><th class="tbopt">&nbsp;数据库服务器IP:</th>
        <td><input type="text" id="dbIp" name="dbIp" value="localhost" size="35" class="txt"></td>
        <td>&nbsp;默认不需要修改</td>
        </tr>

        <tr><th class="tbopt">&nbsp;数据库服务端口:</th>
        <td><input type="text" id="dbPort" name="dbPort" value="3307" size="35" class="txt"></td>
        <td>&nbsp;默认不需要修改</td>
        </tr>

        <tr><th class="tbopt">&nbsp;数据库名称:</th>
        <td><input type="text" id="dbName" name="dbName" value="<%=productInfo.productId%>" size="35" class="txt"></td>

        <td>&nbsp;默认不需要修改</td>
        </tr>

        <tr><th class="tbopt">&nbsp;数据库用户名:</th>
        <td><input type="text" id="dbUser" name="dbUser" value="root" size="35" class="txt"></td>
        <td>&nbsp;默认不需要修改</td>
        </tr>

        <tr><th class="tbopt">&nbsp;数据库密码:</th>
        <td><input type="text" name="dbPassword" value="" size="35" class="txt"></td>
        <td>&nbsp;默认是空，不需要填写</td>
        </tr>
        </table>
      </div>
      <table class="tb2">
      <tr><th class="tbopt">&nbsp;</th>
      <td><input type="submit" name="submitname" value="下一步" class="btn">
      </td>
      <td>&nbsp;</td>
      </tr>
      </table>
      </form>
      <div class="footer">&copy;2010 - 2017 <a href='<%=companyHref%>'><%=productName%></a> Inc.</div>
    </div>
  </div>
</body>
</html>